<!DOCTYPE htm PUBLIC "-//W3C//DTD Xhtm 1.0 Transitional//EN" "DTD/xhtm1-transitional.dtd">
<htm xmlns="http://www.w3.org/1999/xhtm" xml:lang="de" lang="de">
<head>
 <meta http-equiv="content-type" content="text/htm; charset=iso-8859-1" />
 <meta http-equiv="content-style-type" content="text/css" />
 <meta name="author" content="Arlsair" />
 <meta name="date" content="2004-01-22" />
 <title>GreedyHMA</title>
 <link rel="stylesheet" type="text/css" href="../../style.css" />
</head><body>
<h1>GreedyHMA</h1>

<h2>&Uuml;bersicht</h2>
<b>Autor:</b> Tom Barry<br />
<b>Version:</b> 0.4.1.0<br />
<b>Download:</b> <a href="http://mywebpages.comcast.net/trbarry/downloads.htm" target="_blank">http://mywebpages.comcast.net/trbarry/downloads.htm</a><br />
<b>Kategorie:</b> Deinterlacing &amp; Pulldown<br />
<b>Anforderungen:</b>
<ul>
  <li>YUY2 Farbformat</li>
  <li>SSEMMX (=ISSE) f&auml;hige CPU</li>
</ul>
<hr size=2 width="100%" align=center>

<h2>Description</h2>

<p>NOTE - This version is for Avisynth 2.5 (YUY2 only). Use the dll in the "Older" folder for Avisynth 2.0x.<br>
<br>
        GreedyHMA - Greedy (High Motion for Avisynth)<br>
<br>
        GreedyHMA.dll is an Avisynth filter that executes DScaler's Greedy/HM algorithm code to
perform pulldown matching, filtering, and video deinterlace.<br>
<br>
        Just unzip the contents into your Avisynth directory, or somewhere. As the script shows,
I made a subdirectory under Avisynth just to keep it separate.<br>
<br>
        Following is Bikes.avs, one of the scripts I was testing:</p>

<pre>LoadPlugin(&quot;d:\AVISynth\GreedyHMA\Debug\GreedyHMA.dll&quot;)
clip = AVISource(&quot;c:\vcr\bikes.avi&quot;)
return clip.GreedyHMA(1,0,4,0,0,0,0,0)</pre>

<p>It specifies the file spec (change yours) and asks for TopFirst and AutoPulldown to be
turned on, with decimation (frame dropping) to 24 fps.  I've so far tested it only        with Avisynth/VirtualDub.&nbsp;</p>

<h3>Warning</h3>

<p>Previous to V 0.4.0.0 I was telling everyone that TopFirst almost always work better but
that just turned out to be because of a bug in the BottomFirst GreedyHMA code. So you
should verify any previous tests here. Some folks were getting unnecessary weave or
deinterlace artifacts because of this.<br>
<br>
        On some sources I get slightly better results with TopFirst on (say HDTV captures) but others
are better with it off. I notice it's possible to run 2 copies of Vdub and do a frame by frame
compare. There doesn't seem to be to much difference but a still compare of two frames (look at
diagonals) will usually show one to be better. You can just look at the VirtualDub
inputs for this. It's not necessary to actually create any output files yet.<br>
<br>
		For Versio 0.4.0.0 I've added two new filter scripts to the zip to tell for sure whether you		should use TopFirst. Modify the BottomFirst.avs script to point to your file and load it
into VirtualDub. Then single step a few frames. Ignore the single line up and down jitter
but watch to see if every other frame seems to go backwards. If so you probably need TopFirst.
Try the TopFirst.avs script to verify that. Neither of these two scripts depends upon GreedyHMA.<br>
<br>
<br>
		After finding the correct TopFirst setting (T=0 or 1) then the apply the following guidelines,
substituting the TopFirst setting for 'T'.<br>
<br>
		If you think you have mostly film source, or DVD2AVI says so, then use:<br>
<br>
			GreedyHMA(T,0,5,0,0,0,0,0)		# which is Force Film+Decimation to 24 fps.<br>
<br>
		If you have all video, use:<br>
<br>
			GreedyHMA(T,0,0,0,0,0,0,0)  	# for 30 FPS output (25 FPS PAL), or<br>
			GreedyHMA(T,0,3,0,0,0,0,0)      # for 24 FPS output<br>
<br>
		and when you don't know, don't care, or it's all mixed up, just make it auto:<br>
<br>
			GreedyHMA(T,0,4,0,0,0,0,0)		# the all purpose most automatic setting (NTSC), or<br>
			GreedyHMA(T,0,1,0,0,0,0,0)		# the all purpose most automatic setting (PAL)<br>
<br>
<br>
		Other switches can be added as below:</p>

<h3>GreedyHMA Parameterlist</h3>

<pre>return clip.GreedyHMA(TopFirst, SwapFields, AutoPullDown, MedianFilter, VerticalFilter, EdgeEnhance, GoodPullDownLvl, BadPullDownLvl)</pre>

<p>All the values are integer, 0=no, 1=yes:<br>
<br>
<b>
          TopFirst</b> - assume the top field, lines 0,2,4,... should be displayed first.
The default is the supposedly more common BottomFirst but on ATSC captures from my WinTV-HD card TopFirst still works better for me.<br>
<br>
<b>
          SwapFields</b> - for busted capture drivers that put lines 1,3,5.. over lines 0,2,4...<br>
<br>
<b>
          AutoPullDown</b> - Sets what types of Pulldown processing is desired. Valid parm values are:<br>
<br>
            0 - No pulldown, just do pure deinterlace (Force Video). Doesn't drop
any frames so FPS is left at 30 FPS, or wherever. Doesn't decimate<br>
                (pentimate?). Use if you have (and want) 30 fps video source or maybe 25 FPS PAL video.<br>
<br>
            1 - Auto Pulldown. Automatically decide which frames should be IVTC'd                or deinterlaced, depending upon the settings of the Good and Bad
Pulldown Lvls (see below). Don't decimate. This is best if you have mixed film and video and wan't 30 fps output. Also better
for PAL sources.<br>
<br>
            2 - Pulldown only (Force Film). Assume film source, always do IVTC and
never deinterlace. Don't decimate. Use for PAL film source.<br>
<br>
            Values 3-5 match those above but with frame dropping (Decimation, pentimation?)
Five frames at a time are looked at and the one most likely to be a duplicate is dropped, thus lowering the FPS from, say, 30 to 24.<br>
<br>
            3 - Deinterlace (Force Video) but with frame dropping. Use for NTSC video
if you still want to decimate. With video source there really are no proper fields to drop, but this will drop the ones looking most like
dupes.<br>
<br>
            4 - Auto Pulldown with frame dropping. The best (most automatic) setting.
Works in most cases, at least if I get all the bugs out.<br>
<br>
            5 - Pulldown only (Force Film) with frame dropping. This will give the best
results if you have 100% properly mastered NTSC film source with no video sections and not too many edits. It can adjust for most scene                changes and changes in pulldown cadence, but not mixed up fields.<br>
<br>
            I haven't tried to see what's best with all this yet. Pulldown stuff's still
not perfect. But unless you're certain, you can often leave this on 4 (Auto). It should still handle high motion video sports ok. If it falls into			deinterlace mode too often during film processing you can try raising the
Bad Pulldown Level a bit.<br>
<br>
<br>
   ***** NOTE!  THE MEDIAN FILTER IS DISABLE FOR THIS RELEASE. *****<br>
<br>
<b>
          MedianFilter (temporal)</b> - Helps get rid of noise if needed but causes a	        2 field video delay. (Otherwise there's a 1 field delay) Specifying 1
turns it on using the current default of 3 (may change) but you can also            specify 2-255 to override this. But values over about 3-5 can cause motion
artifacts in fast motion video.<br>
<br>
            See note above. I broke the Median Filter adding frame dropping since it runs
at a delay of 2 instead of everything else. It seemed less important so I just disable it for now. The parm is currently ignored.<br>
<br>
			The Median Filter is an unneeded complication while GreedyHMA is new because
it changes the internal timing logic, confusing testing of some parts of the Avisynth specific code. I'll re-enable it after everything else is solid, but
for now it's still disabled.<br>
<br>
    ***** NOTE *****<br>
<br>
<b>
          VerticalFilter</b> - Not only gets rid of noise but also some deinterlacing
artifacts since it's done last, after deinterlace. Useful if you are going to down scale. Use only values 0,1 for parm.  This also helps compression.<br>
<br>
<b>
          EdgeEnhance</b> (horizontal) - Add a little sharpness to full res video. This  	        one can also use parm values of 2-100. The default is currently 50 if
1 is specified.  I may also support negative values in the future, making it a horizontal filter to help set up for downscaling.<br>
<br>
<b>
          Good Pulldown Lvl</b> - This is a number from 1-255 that must be exceeded before
GreedyHMA will do pulldown for a frame. This parm is honored only when Auto Pulldown is also turned on (AP=1 or 4). The default is subject to change but is
currently set at 90. But you will get the default value just by specifying 0, which is recommended for most cases. It is really just a few frame average
of the savings in comb/weave factors by properly matching frames.<br>
<br>
<b>
          Bad Pulldown Lvl</b> - This is a number from 1-255 that must NOT be exceeded before
GreedyHMA will do pulldown for a frame. This parm is honored only when Auto Pulldown is also turned on. The default is subject to change but is
currently set at 85. But you will get the default value just by specifying 0, which is recommended for most cases. This is really just a measure of
how bad a frame's comb/weave factors would be increased if we did pure field matching.<br>
<br>
			New with V 0.4.0.0 when Force Fiim is specified (AP=2,5) the Bad Pulldown level
defaults to an impossibly huge amount. But it may now be overridden to still			deinterace on extreme frames of interlacing artifacts. I haven't tested to find
the optimum value but it's probably less than 150 or so. Specifying 0 gives the defualt of always Force Film.<br>
<br>
        For now, all 8 parms must be present, there is no error checking, and no more doc except
about Greedy/HM at <a href="http://www.dscaler.org"> www.dscaler.org</a></p>

<h3>Known issues and limitation</h3>

<p>1) 	THIS IS FOR SSE MACHINES ONLY!<br>
<br>
        This is written like the advanced options of DScaler Greedy/HM, partly in assembler for
SSE machines only.  I've so far got zero error checking in it, so it will just CRASH if
you don't have at least a faster Celeron, P-III, Athlon, or higher. I'm not sure if this
will be corrected in the future, but I might if time permits.<br>
<br>
        2) 	Currently no error checking or messages. I haven't figured out how to issue messages
in Avisynth yet, and there is a bunch of stuff I should check that I'm not.<br>
<br>
        3) 	Assumes YUV (YUY2) Frame Based input. Use an AVIsynth function to convert first if
needed.<br>
<br>
        4)	Currently limited to a frame resolution of 1928x1088 pixels.<br>
<br>
		5)  Fixed<br>
<br>
        6)	There is a strange bug that I don't understand at all. If you add a new or changed
GreedyHMA.dll to your machine, the first time you run VirtualDub/Avisynth/GreedyHMA
then VirtualDub may stop responding. If you then use the Task Manager to cancel	        VirtualDub it will run after that.  A work-around seems to be to first open any
other AVI file in VirtualDub the first time you bring it up after installing GreedyHMA,
before opening any Avisynth scripts.  Later notes: it doesn't depend upon GreedyHMA at
all, it happens without it on my machine, but I still don't understand it.<br>
<br>
        7)  Currently works properly only if fed a screen width in pixels that is a multiple of 16.
Otherwise it may produce garbage at the right of the screen that you may have to crop.<br>
<br>
        8)  As stated above, the Median Filter option is temporarily ignored.<br>
<br>
<br>
        Please send comments to Tom Barry (trbarry@trbarry.com)<br>
<br>
        Temporary file locations:<br>
<br>
        For now, see www.trbarry.com/GreedyHMA.zip<br>
<br>
        The source is, or will soon be, in the DScaler open source project. www.dscaler.org		(also now in the zip)<br>
<br>
<br>
Finally, the following is a slightly abridged copy of the Greedy (High Motion) summary from
the DScaler Help page:<br>
<br>
GREEDY (HIGH MOTION) DEINTERLACE METHOD<br>
<br>
WHAT IT DOES: (Basic)&nbsp;<br>
<br>
The plugin works at two different levels. By default, at the Basic Level, it is a normal
DScaler deinterlace method, with the following features:<br>
<br>
- A merge of Blended Clip, Greedy (Low Motion), and some new stuff<br>
<br>
- Greedy implied pulldown, like the Greedy (Low Motion) method<br>
<br>
- Parm blending like the Blended Clip method, for less sizzling.<br>
<br>
- Lookahead motion detection<br>
<br>
- Diagonal Jaggie Reduction (DJR ;-) ) to smooth out the stair step effect in moving
diagonal lines. This is accomplish by horizontally smoothing only the rapidly moving
pixels, leaving the stationary ones alone. If a diagonal edge is not moving then it
won't be jagged anyway under Greedy (High Motion). I've previously somewhere here
posted a couple snaps of some hard to handle Video Essentials scenes off my test
machine and a $135 non-progressive DVD player. See the Flag and the Lampposts.<br>
<br>
- Slider adjustments for Max Comb, Motion Threshold, and Motion Sensitivity. However the
defaults should be okay for most cases.<br>
<br>
<br>
WHAT IT DOES: (Advanced)<br>
<br>
There is also an Advanced Level (experimental) which is invoked if you check any of the
boxes in the Method UI panel. You won't be able to do this unless you are running a
machine supporting the Intel SSE instruction set (only integer SSE instructions are
needed). The Advanced options should run on Athlons, Intel P-III, P4, and the faster
Celerons.<br>
<br>
When using the Advanced Features Greedy (HM) maintains its own internal history of the last
4 video input fields. This means it must be able to examine every field and you can't use
it at the same time as DScaler's regular Auto_Pulldown option.&nbsp;<br>
<br>
The new check box enabled features are:<br>
<br>
- Built in 3:2, 2:2, an n:m Pulldown. This does pulldown matching, not removal, so all
frames are displayed. I think this eventually will work better with video overlays and
live TV viewing that is extensively edited, but it still needs improvement.<br>
<br>
- In-Between Frames. This gives judder reduction for those of us with fixed 60 HZ
RTPV's. In a 3:2 pulldown situation it will select an appropriate pair of fields to
average once out of every 5 frames. This can effectively display every new input frame
2 1/2 times. It will cause a small amount of motion blur every fifth frame but I
personally leave it turned on all the time now for a smoother film picture sequence.
It will also work with 2:2 pulldown (I think) but there one half of the frames will be
averaged and the motion blur may not be acceptable.<br>
<br>
- Adjustable Edge Enhancement. This is due to an idea posted by this forum's MR. Wigggles.
It enhances only a small amount, on the horizontal axis. When turned on you can use a<br>
slider to adjust it.<br>
<br>
- Adjustable Median Filter. Also due to Mr. Wigggles, this can help filter noise. However
if set over about 3-5 it will also cause motion artifacts on fast moving scenes. Also has
a slider.<br>
<br>
- Vertical Filter. This is a post-deinterlace software vertical filter that can remove
both noise and some leftover deinterlace artifacts. It gives results similar to the
hardware version available on the Advanced Video Flags screen, but not so extreme and
without the jitter.</p>
</body>
</html>
